//
//  ViewController.m
//  UI_15_网易上面的滑动button
//
//  Created by li cheng on 16/8/3.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "MyCollectionViewCell.h"
#import "LCCollectionViewLayout.h"
@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, LCCollectionViewLayoutDelegate>
@property (nonatomic, strong) NSArray *buttonTitleArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _buttonTitleArray = @[@"头回答是发送到发送到条",@"网易号",@"大连",@"轻松一刻",@"段子",@"哒哒趣很多时候闻",@"彩好的时候多少漂",@"快来看美女"];
    LCCollectionViewLayout *layout = [[LCCollectionViewLayout alloc] init];
    layout.delegate = self;
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:collectionView];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.bounces = NO;
    self.edgesForExtendedLayout = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"MyCollectionViewCell"];
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld", indexPath.row);
    NSString *string = _buttonTitleArray[indexPath.row];
    NSLog(@"%@", string);
    CGRect newRect =  [string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    NSLog(@"+++++++++++++++%f", newRect.size.height);
    return newRect.size.width;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _buttonTitleArray.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCollectionViewCell" forIndexPath:indexPath];
    [cell.button setTitle:_buttonTitleArray[indexPath.row] forState:UIControlStateNormal];
//    NSString *string = _buttonTitleArray[indexPath.row];
//    cell.label.text = string;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
